#pragma once

#ifdef WIN32
	#ifndef WIN32_LEAN_AND_MEAN
	#define WIN32_LEAN_AND_MEAN
	#endif
	#include <winsock2.h>
	#include <windows.h>
#else
	#include <unistd.h>
	#include <sys/socket.h>
	#include <netinet/in.h>
	#include <arpa/inet.h>
	#include <sys/select.h>
	#include <sys/time.h>
	#include <sys/types.h>
	#include <unistd.h>
	#include <netdb.h>
	#include <sys/ioctl.h>
	#include <fcntl.h>
	#define SOCKET int
#endif

class LSocket
{
public:
	LSocket();
	~LSocket(void);
	static bool InitSock();

	bool Connect(const char *ip, unsigned int port);

	void Send(const char *pcBuf, unsigned int uiLen);
	void SendLenAndData(const char *pcBuf, unsigned int uiLen);
	int Recv(char *pcBuf, unsigned int uiLen);

	void Close();

	inline void SetFD(int fd){ this->m_fd = fd;}
	inline bool ValidFD(){ return this->m_fd>0?true:false; }

private:
	int m_fd;
};

